package com.tinno.chargelauncher.utils;

import android.content.Context;
import android.util.Log;

import java.lang.reflect.Method;

public class Utils {

	private static final String TAG = Utils.class.getSimpleName();

	/**
	 * 通过反射方法调用StatusBarManager 来禁用statusbar
	 * @param context
	 * @param disable
	 */
	public static void disableStatusBar(Context context, boolean disable){
		Log.d(TAG, "disableStatusBar & disableNaviBar");

		Object statusBarService = context.getSystemService("statusbar");

		Class<?> statusBarManager = null;

		try {
			statusBarManager = Class.forName("android.app.StatusBarManager");
			try {
				final Method disable_statusBarFeatures = statusBarManager.getMethod("disable", int.class);
				try {
					disable_statusBarFeatures.setAccessible(true);
					if (disable){
						/**
						 * @DISABLE_NONE:0x00000000
						 * @DISABLE_EXPAND:0x00010000
						 * @DISABLE_NOTIFICATION_ICONS:0x00020000
						 * @DISABLE_NOTIFICATION_ALERTS:0x00040000
						 * @DISABLE_SYSTEM_INFO:0x00100000
						 * @DISABLE_HOME:0x00200000
						 * @DISABLE_SEARCH:0x02000000
						 * @DISABLE_RECENT:0x01000000
						 * @DISABLE_BACK:0x00400000
						 */
						disable_statusBarFeatures.invoke(statusBarService, 0x00010000 | 0x00020000 | 0x00040000 | 0x00100000 | 0x00200000 | 0x02000000 | 0x01000000 | 0x00400000);
					}else {
						disable_statusBarFeatures.invoke(statusBarService, 0x00000000);
					}
				}catch (Exception e){
					Log.e(TAG, "disableStatusBar & disableNaviBar" + e.getMessage(), e);
				}
			} catch (Exception e){
				Log.e(TAG, "disableStatusBar & disableNaviBar" + e.getMessage(), e);
			}
		}catch (Exception e){
			Log.e(TAG, "disableStatusBar & disableNaviBar" + e.getMessage(), e);
		}
	}
}
